home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / blankery / blanker / source / blankers / fade / fade.c < prev    next >
C/C++ Source or Header  |  1993-07-03  |  6KB  |  237 lines

  1. /*
  2.  *  Source machine generated by GadToolsBox V2.0b
  3.  *  which is (c) Copyright 1991-1993 Jaba Development
  4.  *
  5.  *  GUI Designed by : Michael D. Bayne
  6.  */
  7.  
  8. #include <exec/types.h>
  9. #include <intuition/intuition.h>
  10. #include <intuition/classes.h>
  11. #include <intuition/classusr.h>
  12. #include <intuition/imageclass.h>
  13. #include <intuition/gadgetclass.h>
  14. #include <libraries/gadtools.h>
  15. #include <graphics/displayinfo.h>
  16. #include <graphics/gfxbase.h>
  17. #include <clib/exec_protos.h>
  18. #include <clib/intuition_protos.h>
  19. #include <clib/gadtools_protos.h>
  20. #include <clib/graphics_protos.h>
  21. #include <clib/utility_protos.h>
  22. #include <string.h>
  23. #include <clib/diskfont_protos.h>
  24.  
  25. #include "Fade.h"
  26.  
  27. struct Screen         *Scr = NULL;
  28. UBYTE                 *PubScreenName = NULL;
  29. APTR                   VisualInfo = NULL;
  30. struct Window         *FadeWnd = NULL;
  31. struct Gadget         *FadeGList = NULL;
  32. struct IntuiMessage    FadeMsg;
  33. struct Gadget         *FadeGadgets[4];
  34. UWORD                  FadeLeft = 0;
  35. UWORD                  FadeTop = 12;
  36. UWORD                  FadeWidth = 237;
  37. UWORD                  FadeHeight = 28;
  38. UBYTE                 *FadeWdt = (UBYTE *)"Fade Prefs";
  39. struct TextAttr       *Font, Attr;
  40. UWORD                  FontX, FontY;
  41. UWORD                  OffX, OffY;
  42. struct TextFont       *FadeFont = NULL;
  43.  
  44. UWORD FadeGTypes[] = {
  45.     SLIDER_KIND,
  46.     BUTTON_KIND,
  47.     BUTTON_KIND,
  48.     BUTTON_KIND
  49. };
  50.  
  51. struct NewGadget FadeNGad[] = {
  52.     53, 2, 154, 10, (UBYTE *)"_Delay", NULL, GD_DELAY, PLACETEXT_LEFT, NULL, (APTR)DELAYClicked,
  53.     9, 14, 66, 12, (UBYTE *)"_Ok", NULL, GD_OK, PLACETEXT_IN, NULL, (APTR)OKClicked,
  54.     162, 14, 66, 12, (UBYTE *)"_Cancel", NULL, GD_CANCEL, PLACETEXT_IN, NULL, (APTR)CANCELClicked,
  55.     85, 14, 66, 12, (UBYTE *)"_Test", NULL, GD_TEST, PLACETEXT_IN, NULL, (APTR)TESTClicked
  56. };
  57.  
  58. ULONG FadeGTags[] = {
  59.     (GTSL_Max), 59, (GTSL_Level), 15, (GTSL_MaxLevelLen), 4, (GTSL_LevelFormat), (ULONG)"%2ld", (GTSL_LevelPlace), (PLACETEXT_RIGHT), (PGA_Freedom), LORIENT_HORIZ, (GA_RelVerify), TRUE, (GT_Underscore), '_', (TAG_DONE),
  60.     (GT_Underscore), '_', (TAG_DONE),
  61.     (GT_Underscore), '_', (TAG_DONE),
  62.     (GT_Underscore), '_', (TAG_DONE)
  63. };
  64.  
  65. static UWORD ComputeX( UWORD value )
  66. {
  67.     return(( UWORD )((( FontX * value ) + 3 ) / 6 ));
  68. }
  69.  
  70. static UWORD ComputeY( UWORD value )
  71. {
  72.     return(( UWORD )((( FontY * value ) + 4 ) / 8 ));
  73. }
  74.  
  75. static void ComputeFont( UWORD width, UWORD height )
  76. {
  77.     Forbid();
  78.     Font = &Attr;
  79.     Font->ta_Name = (STRPTR)GfxBase->DefaultFont->tf_Message.mn_Node.ln_Name;
  80.     Font->ta_YSize = FontY = GfxBase->DefaultFont->tf_YSize;
  81.     FontX = GfxBase->DefaultFont->tf_XSize;
  82.     Permit();
  83.  
  84.     OffX = Scr->WBorLeft;
  85.     OffY = Scr->RastPort.TxHeight + Scr->WBorTop + 1;
  86.  
  87.     if ( width && height ) {
  88.         if (( ComputeX( width ) + OffX + Scr->WBorRight ) > Scr->Width )
  89.             goto UseTopaz;
  90.         if (( ComputeY( height ) + OffY + Scr->WBorBottom ) > Scr->Height )
  91.             goto UseTopaz;
  92.     }
  93.     return;
  94.  
  95. UseTopaz:
  96.     Font->ta_Name = (STRPTR)"topaz.font";
  97.     FontX = FontY = Font->ta_YSize = 8;
  98. }
  99.  
  100. int SetupScreen( void )
  101. {
  102.     if ( ! ( Scr = LockPubScreen( PubScreenName )))
  103.         return( 1L );
  104.  
  105.     ComputeFont( 0, 0 );
  106.  
  107.     if ( ! ( VisualInfo = GetVisualInfo( Scr, TAG_DONE )))
  108.         return( 2L );
  109.  
  110.     return( 0L );
  111. }
  112.  
  113. void CloseDownScreen( void )
  114. {
  115.     if ( VisualInfo ) {
  116.         FreeVisualInfo( VisualInfo );
  117.         VisualInfo = NULL;
  118.     }
  119.  
  120.     if ( Scr        ) {
  121.         UnlockPubScreen( NULL, Scr );
  122.         Scr = NULL;
  123.     }
  124. }
  125.  
  126. int HandleFadeIDCMP( void )
  127. {
  128.     struct IntuiMessage    *m;
  129.     int            (*func)();
  130.     BOOL            running = TRUE;
  131.  
  132.     while( m = GT_GetIMsg( FadeWnd->UserPort )) {
  133.  
  134.         CopyMem(( char * )m, ( char * )&FadeMsg, (long)sizeof( struct IntuiMessage ));
  135.  
  136.         GT_ReplyIMsg( m );
  137.  
  138.         switch ( FadeMsg.Class ) {
  139.  
  140.             case    IDCMP_REFRESHWINDOW:
  141.                 GT_BeginRefresh( FadeWnd );
  142.                 GT_EndRefresh( FadeWnd, TRUE );
  143.                 break;
  144.  
  145.             case    IDCMP_VANILLAKEY:
  146.                 running = FadeVanillaKey();
  147.                 break;
  148.  
  149.             case    IDCMP_GADGETUP:
  150.             case    IDCMP_GADGETDOWN:
  151.                 func = ( void * )(( struct Gadget * )FadeMsg.IAddress )->UserData;
  152.                 running = func();
  153.                 break;
  154.         }
  155.     }
  156.     return( running );
  157. }
  158.  
  159. int OpenFadeWindow( void )
  160. {
  161.     struct NewGadget    ng;
  162.     struct Gadget    *g;
  163.     UWORD        lc, tc;
  164.     UWORD        wleft = FadeLeft, wtop = FadeTop, ww, wh;
  165.  
  166.     ComputeFont( FadeWidth, FadeHeight );
  167.  
  168.     ww = ComputeX( FadeWidth );
  169.     wh = ComputeY( FadeHeight );
  170.  
  171.     wleft = ( Scr->Width - ww )/2 - Scr->WBorRight;
  172.     wtop = ( Scr->Height - wh - Scr->WBorBottom*2 - Font->ta_YSize )/2;
  173.  
  174.     if ( ! ( FadeFont = OpenDiskFont( Font )))
  175.         return( 5L );
  176.  
  177.     if ( ! ( g = CreateContext( &FadeGList )))
  178.         return( 1L );
  179.  
  180.     for( lc = 0, tc = 0; lc < Fade_CNT; lc++ ) {
  181.  
  182.         CopyMem((char * )&FadeNGad[ lc ], (char * )&ng, (long)sizeof( struct NewGadget ));
  183.  
  184.         ng.ng_VisualInfo = VisualInfo;
  185.         ng.ng_TextAttr   = Font;
  186.         ng.ng_LeftEdge   = OffX + ComputeX( ng.ng_LeftEdge );
  187.         ng.ng_TopEdge    = OffY + ComputeY( ng.ng_TopEdge );
  188.         ng.ng_Width      = ComputeX( ng.ng_Width );
  189.         ng.ng_Height     = ComputeY( ng.ng_Height);
  190.  
  191.         FadeGadgets[ lc ] = g = CreateGadgetA((ULONG)FadeGTypes[ lc ], g, &ng, ( struct TagItem * )&FadeGTags[ tc ] );
  192.  
  193.         while( FadeGTags[ tc ] ) tc += 2;
  194.         tc++;
  195.  
  196.         if ( NOT g )
  197.             return( 2L );
  198.     }
  199.  
  200.     if ( ! ( FadeWnd = OpenWindowTags( NULL,
  201.                 WA_Left,    wleft,
  202.                 WA_Top,        wtop,
  203.                 WA_Width,    ww + OffX + Scr->WBorRight,
  204.                 WA_Height,    wh + OffY + Scr->WBorBottom,
  205.                 WA_IDCMP,    SLIDERIDCMP|BUTTONIDCMP|IDCMP_VANILLAKEY|IDCMP_REFRESHWINDOW,
  206.                 WA_Flags,    WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_SMART_REFRESH|WFLG_ACTIVATE|WFLG_RMBTRAP,
  207.                 WA_Gadgets,    FadeGList,
  208.                 WA_Title,    FadeWdt,
  209.                 WA_ScreenTitle,    "Fade Prefs",
  210.                 WA_PubScreen,    Scr,
  211.                 TAG_DONE )))
  212.     return( 4L );
  213.  
  214.     GT_RefreshWindow( FadeWnd, NULL );
  215.  
  216.     return( 0L );
  217. }
  218.  
  219. void CloseFadeWindow( void )
  220. {
  221.     if ( FadeWnd        ) {
  222.         CloseWindow( FadeWnd );
  223.         FadeWnd = NULL;
  224.     }
  225.  
  226.     if ( FadeGList      ) {
  227.         FreeGadgets( FadeGList );
  228.         FadeGList = NULL;
  229.     }
  230.  
  231.     if ( FadeFont ) {
  232.         CloseFont( FadeFont );
  233.         FadeFont = NULL;
  234.     }
  235. }
  236.  
  237.